﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Configuration;
using System.Web.UI;
using System.Text;
using System.IO;
using System.Web.Configuration;

namespace ReconUI
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

        }

        protected void Session_Start(object sender, EventArgs e)
        {
            if (((Request.RawUrl.IndexOf("ReconSignIn.aspx") + 1) == 0) && (Session["usr"] != null))
            {

                if ((Request.RawUrl.IndexOf("Expired.aspx") + 1) == 0)
                {
                    Session.Abandon();

                    Response.Write("<script>window.open('" + HttpRuntime.AppDomainAppVirtualPath + "/ReconSignIn.aspx" + "','_parent');</script>");
                    Response.End();
                }
            }
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            ////capture last exception details
            //Exception lastException = Server.GetLastError();
            //StringBuilder sb = new StringBuilder();
            //sb.AppendLine("Date: " + DateTime.Now.ToLongDateString());
            //sb.AppendLine("Time: " + DateTime.Now.ToLongTimeString());
            //sb.AppendLine("Exception: " + lastException.Message);
            //sb.AppendLine("Exception Type: " + lastException.GetType().FullName);
            //if (lastException.InnerException != null)
            //{
            //    sb.AppendLine("Inner Exception: " + lastException.InnerException);
            //}
            //if (lastException.StackTrace != null)
            //{
            //    sb.AppendLine("Stack Trace: " + lastException.StackTrace);
            //}

            ////write exception details to a disk file
            //using (StreamWriter sw = new StreamWriter(Server.MapPath(WebConfigurationManager.AppSettings["ErrorFile"])))
            //{
            //    sw.Write(sb.ToString());
            //}

            ////clear exception from Server object
            //Server.ClearError();

            ////Navigate to custom error page
            //Server.Transfer("~/ErrorOccurred.aspx", false);

        }

        protected void Session_End(object sender, EventArgs e)
        {
			Session.Clear();
            Session.Abandon();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}